<?php 
require_once("inc_security.php");
//check quyền them sua xoa
checkAddEdit("add");

	//Khai bao Bien
	$fs_action   							= "";
	//Warning Error!
	$fs_errorMsg							= "";
	$fs_redirect							= "add.php";
	$after_save_data						= getValue("after_save_data", "str", "POST", "add.php");
   //$content = getValue("sta_content", 'str', 'POST', '');
	$myform 								= new generate_form();
    $userArr = array(""=>"--Chọn user--");
    $user = new db_query("SELECT * 
										 FROM admin_user
                                         WHERE adm_isadmin != 1
										 ORDER BY adm_id DESC
										 ");
    while($row	=	mysql_fetch_assoc($user->result)){
        $userArr[$row['adm_id']] = $row['adm_loginname'];
    }
    $moduleArr = array(""=>"--Chọn module--");
    $module = new db_query("SELECT * 
										 FROM modules
										 ORDER BY mod_id DESC
										 ");
    while($row	=	mysql_fetch_assoc($module->result)){
        $moduleArr[$row['mod_id']] = $row['mod_name'];
    }
	//Loại bỏ chuc nang thay the Tag Html
	//$myform->removeHTML(0);
	/**
	1). $data_field			: Ten truong
	2). $data_value			: Ten form
	3). $data_type				: Kieu du lieu , 0 : string , 1 : kieu int, 2 : kieu email, 3 : kieu double, 4 : kieu hash password
	4). $data_store			: Noi luu giu data  0 : post, 1 : variable
	5). $data_default_value	: Gia tri mac dinh, neu require thi phai lon hon hoac bang default
	6). $data_require			: Du lieu nay co can thiet hay khong
	7). $data_error_message	: Loi dua ra man hinh
	8). $data_unique			: Chi co duy nhat trong database
	9). $data_error_message2: Loi dua ra man hinh neu co duplicate
	10). $type_form: kiểu form : 1 text ; 2 textarea; 3 kiểu checkbook
	*/
	$myform->add("adu_admin_id", "adu_admin_id", 0, 0, "", 1, "Vui lòng nhập user", 0, ""); //teen các trường và name control
	$myform->add("adu_admin_module_id", "adu_admin_module_id", 0, 0, "", 1, "Vui lòng nhập module", 0, ""); 
    $myform->add("adu_add", "adu_add", 0, 0, "", 0, "", 0, ""); 
    $myform->add("adu_edit", "adu_edit", 0, 0, "", 0, "", 0, ""); 
    $myform->add("adu_delete", "adu_delete", 0, 0, "", 0, "", 0, ""); 
    $myform->addTable($fs_table);
    //Get Action.
	$action	= getValue("action", "str", "POST", "");
	if($action == "execute"){
		$errorMsg = $myform->checkdata();
		if($errorMsg == ""){
			$myform->removeHTML(0);
			$db_insert = new db_execute($myform->generate_insert_SQL());
			unset($db_insert);
			//echo $myform->generate_insert_SQL();
			// Redirect to add new
			
			//Redirect to:
			redirect("add.php");
			exit();
		}
	}	
	//add form for javacheck
	$myform->addFormname("form_name");
	$myform->evaluate();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<?php echo $load_header?>
<?php  $myform->checkjavascript();?>
</head>
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<?php  /*------------------------------------------------------------------------------------------------*/ ?>
<?php echo template_top(translate_text("Add_new_category"))?>
<?php  /*------------------------------------------------------------------------------------------------*/ ?>
	<p align="center" style="padding-left:10px;">
	<?php 
		$form = new form();
		$form->create_form("form_name", $fs_action, "post", "multipart/form-data",'onsubmit="validateForm(); return false;" id="form_name"');
		?>
			<table cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td valign="top" height="200">
						<?php 
						$form->create_table("2");
						?>
						<?php echo $form->text_note('Những ô có dấu sao (<font class="form_asterisk">*</font>) là bắt buộc phải nhập.')?>
						<?php echo $form->errorMsg($fs_errorMsg)?>
						<?php echo $form->select("Chọn user", "adu_admin_id", "adu_admin_id", $userArr, "","Tên người dùng",1)?>
                        <?php echo $form->select("Chọn module", "adu_admin_module_id", "adu_admin_module_id", $moduleArr, "","Tên module",1)?>
                        <?php echo $form->checkbox("Add", "adu_add", "adu_add", 1, ""," Quyền được thêm mới trong module",0)?>
                        <?php echo $form->checkbox("Edit", "adu_edit", "adu_edit", 1, ""," Quyền được sử trong module",0)?>
                        <?php echo $form->checkbox("Delete", "adu_delete", "adu_delete", 1, ""," Quyền được xóa trong module",0)?>
                        <?php  
						$form->close_table();
                        $form->create_table("2");
						?>
						<?php echo $form->button("submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "submit" . $form->ec . "reset", "Cập nhật" . $form->ec . "Làm lại", "Cập nhật" . $form->ec . "Làm lại", '' . $form->ec . '', "");?>
						<?php  
						$form->close_table();
						?>
						<?php echo $form->hidden("action", "action", "execute", "");?>
					</td>
				</tr>					
			</table>
		<?php 
		$form->close_form();
		unset($form);
		?>
	</p>
<?php echo template_bottom() ?>
<?php  /*------------------------------------------------------------------------------------------------*/ ?>
</body>
</html>